var t = require("../../../@babel/runtime/helpers/defineProperty"), a = getApp();

Page({
    data: {
        language: "",
        countDownList: [],
        actEndTimeList: [],
        groupDetail: {},
        goodsDetail: {},
        has_many_success_member: "",
        has_many_success_member_count: "",
        member_num: "",
        gooddatas: {},
        id: "",
        showOpenGroup: !1,
        goodsInfo: {},
        goodsDescription: "",
        popPrice: 0,
        goodsId: "",
        activityId: "",
        isOpen: 0,
        status: 0,
        action: 0,
        activityTest: "",
        btnTest: "",
        btnStatus: !1,
        option_level_id: "",
        nowTime: new Date().getTime() / 1e3,
        isCheckActivity: !0,
        shareData: {},
        optionsId: 0,
        popupSpecs: !1,
        goodsCount: 1,
        optionsMaxCount: 1,
        popupSpecs2: !1,
        popThumb: "",
        popStock: 0,
        specsManage: [],
        popupModeshow: !0
    },
    onLoad: function(t) {
        t.mid && a._setMid(t.mid), console.log(t, "参数"), this._getData();
    },
    onReady: function() {
        var t = wx.getStorageSync("langIndex");
        this.setData({
            language: t.en
        });
    },
    onShow: function() {
        wx.showShareMenu({
            withShareTicket: !1,
            menus: [ "shareAppMessage", "shareTimeline" ]
        });
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareTimeline: function() {
        var t = wx.getStorageSync("yz_uid"), a = "";
        return t && (a = t), {
            query: "id=".concat(this.options.id, "&mid=").concat(a)
        };
    },
    onShareAppMessage: function(t) {
        var a = wx.getStorageSync("yz_uid"), s = "";
        return a && (s = a), {
            title: "" == this.data.gooddatas.share_title ? this.data.gooddatas.title : this.data.gooddatas.share_title,
            path: "/packageE/grab_group/grab_group_detail/grab_group_detail?id=" + this.options.id + "&mid=" + s
        };
    },
    getShare: function() {
        var t = this, s = a.getNetAddresss("plugin.snatch-regiment.api.index.getSnatchData");
        s += "&art=getShare", a._getNetWork({
            url: s,
            success: function(a) {
                var s = a.data;
                1 == s.result ? t.setData({
                    shareData: s.data.getShare
                }) : wx.showToast({
                    icon: "none",
                    title: s.msg,
                    duration: 1500
                });
            }
        });
    },
    _getData: function() {
        var t = this, s = a.getNetAddresss("plugin.snatch-regiment.api.index.getSnatchData");
        s += "&leader_id=" + this.options.id + "&art=raidDetail", a._getNetWork({
            url: s,
            success: function(a) {
                var s = a.data;
                1 == s.result ? (t.setData({
                    gooddatas: s.data.raidDetail,
                    "gooddatas.team_end_time": Number(s.data.raidDetail.team_end_time),
                    "gooddatas.activity_end_time": Number(s.data.raidDetail.activity_end_time)
                }), t.initPopView(), t.getShare()) : wx.showToast({
                    icon: "none",
                    title: s.msg,
                    duration: 1500
                });
            }
        });
    },
    checkActivity: function() {
        var t = this;
        if (0 != this.data.popPrice) {
            var s = a.getNetAddresss("plugin.snatch-regiment.api.index.getSnatchData");
            s += "&at_id=" + this.data.gooddatas.activity_id + "&art=inspectOverrun&option_id=" + this.data.optionsId + "&goods_id=" + this.data.gooddatas.goods_id + "&total=" + this.data.goodsCount + "&leader_id=" + this.options.id, 
            a._getNetWork({
                url: s,
                success: function(a) {
                    var s = a.data;
                    1 == s.result ? (t.setData({
                        isCheckActivity: !0
                    }), t.submitAction()) : (t.setData({
                        isCheckActivity: !1
                    }), wx.showToast({
                        icon: "none",
                        title: s.msg,
                        duration: 1500
                    }));
                }
            });
        } else wx.showModal({
            title: "提示",
            showCancel: !1,
            content: "开团/参团金额不正确，不能为0",
            success: function(t) {}
        });
    },
    gotoList: function() {
        wx.navigateTo({
            url: "/packageE/grab_group/grab_group_home/grab_group_home"
        });
    },
    gotoOrder: function() {
        var t = this.options.id;
        wx.navigateTo({
            url: "/packageA/member/orderdetail/orderdetail?order_id=" + t + "&orderType=grabGroup"
        });
    },
    showPopView: function() {
        if (1 == this.data.gooddatas.has_option && (a._isTextEmpty(this.data.optionsId) || 0 == this.data.optionsId)) for (var t = 0; t < this.data.gooddatas.has_many_specs.length; t++) this.data.gooddatas.has_many_specs[t].description = this.data.gooddatas.has_many_specs[t].specitem[0].id, 
        this.selectSpecs(this.data.gooddatas.has_many_specs[t].specitem[0], "first", t);
        this.setData({
            popupSpecs: !0,
            popupModeshow: !1
        });
    },
    popupSpecsbtn: function() {
        this.setData({
            popupSpecs: !1,
            popupModeshow: !0
        });
    },
    initPopView: function() {
        if (this.setData({
            "gooddatas.has_option": this.data.gooddatas.has_many_specs.length > 0 ? 1 : 0
        }), 1 == this.data.gooddatas.has_option) {
            this.setData({
                popPrice: this.data.gooddatas.min_price + "-" + this.data.gooddatas.max_price,
                popThumb: this.data.gooddatas.thumb,
                popStock: this.data.gooddatas.stock,
                goodsDescription: "选择"
            });
            for (var t = 0; t < this.data.gooddatas.has_many_specs.length; t++) this.setData({
                goodsDescription: this.data.goodsDescription + " " + this.data.gooddatas.has_many_specs[t].title
            });
        } else this.setData({
            popThumb: this.data.gooddatas.thumb,
            popStock: this.data.gooddatas.stock,
            popPrice: this.data.gooddatas.price,
            goodsDescription: "",
            optionsMaxCount: this.data.gooddatas.stock
        });
    },
    inputGoodsNum: function(t) {
        var s = parseInt(t.detail.value), o = this.data.goodsCount;
        8 == t.detail.keyCode && a._isTextEmpty(t.detail.value) ? this.setData({
            goodsCount: ""
        }) : s ? this.setData({
            goodsCount: s
        }) : this.setData({
            goodsCount: o
        });
    },
    reduceGoods: function() {
        var t = this.data.goodsCount;
        1 != this.data.goodsCount && 0 != this.data.goodsCount && this.setData({
            goodsCount: t - 1
        });
    },
    addGoods: function() {},
    selectSpecs: function(a, s, o) {
        var e = {}, i = 0;
        if ("first" == s ? (i = o, e = a) : "sku_swiper" == s ? e = a : (i = a.currentTarget.dataset.specsidex, 
        e = a.currentTarget.dataset.specitem), e.c) return !1;
        this.setData(t({}, "gooddatas.has_many_specs[" + i + "].description", e.id)), this.manageSpecs(e), 
        this.setGoodsSpecs(e), this.setGoodsSpecsChangeInfo(), this.getMaxCount();
    },
    manageSpecs: function(t) {
        var a = new Object(), s = this.data.specsManage;
        if (a.id = t.id, a.specid = t.specid, a.title = t.title, s.length > 0) {
            for (var o = 0; o < s.length; o++) s[o].specid == a.specid && s.splice(o, 1);
            s.push(a);
        } else s.push(a);
        if (s.length == this.data.gooddatas.has_many_specs.length) {
            for (var e = [], i = 0; i < this.data.gooddatas.has_many_specs.length; i++) for (var d = 0; d < s.length; d++) if (this.data.gooddatas.has_many_specs[i].id == s[d].specid) {
                e.push(s[d]);
                break;
            }
            s = e;
        }
        this.setData({
            specsManage: s
        }), this.setGoodsDescription();
    },
    setGoodsDescription: function() {
        var t = "", a = this.data.specsManage;
        if (a.length == this.data.gooddatas.has_many_specs.length) {
            t = "已选择 ";
            for (var s = 0; s < a.length; s++) t += a[s].title + " ";
            this.setData({
                goodsDescription: t
            });
        } else {
            t = "请选择 ";
            for (var o = 0; o < this.data.gooddatas.has_many_specs.length; o++) for (var e = 0; e < a.length; e++) if (this.data.gooddatas.has_many_specs[o].id != a[e].specid) {
                t += this.data.gooddatas.has_many_specs[o].title + " ";
                break;
            }
            this.setData({
                goodsDescription: t
            });
        }
    },
    setGoodsSpecs: function(t) {
        for (var a = 0; a < this.data.gooddatas.has_many_specs.length; a++) t.specid, this.data.gooddatas.has_many_specs[a].id;
    },
    setGoodsSpecsStatus: function(t, a) {
        var s = [];
        if (this.data.gooddatas && this.data.gooddatas.has_many_options) for (var o = 0; o < this.data.gooddatas.has_many_options.length; o++) for (var e = this.data.gooddatas.has_many_options[o].specs.split("_"), i = 0; i < e.length; i++) if (e[i] == a) return void s.push(this.data.gooddatas.has_many_options[o]);
        for (var d = 0; d < s.length; d++) for (var n = s[d].specs.split("_"), h = 0; h < n.length; h++) if (n[h] != a && 0 == s[d].stock) for (var r = 0; r < t.length; r++) n[h] == t[r].id && (t[r].c = !0); else if (n[h] != a && s[d].stock > 0) for (var p = 0; p < t.length; p++) n[h] == t[p].id && (t[p].c = !1);
        return t;
    },
    setGoodsSpecsChangeInfo: function() {
        var t = this.data.specsManage;
        if (t.sort(function(t, a) {
            return t.id - a.id;
        }), t.length == this.data.gooddatas.has_many_specs.length) {
            for (var s = "", o = 0; o < t.length; o++) s += t[o].id + "_";
            if (s = s.substring(0, s.length - 1), this.data.gooddatas && this.data.gooddatas.has_many_options) for (var e = 0; e < this.data.gooddatas.has_many_options.length; e++) if (s == this.setGoodsSpecsBySort(this.data.gooddatas.has_many_options[e].specs)) {
                this.setData({
                    activeSkuIndex: e,
                    popPrice: this.data.gooddatas.has_many_options[e].product_price,
                    popThumb: a._isTextEmpty(this.data.gooddatas.has_many_options[e].thumb) ? this.data.gooddatas.thumb : this.data.gooddatas.has_many_options[e].thumb,
                    popStock: this.data.gooddatas.has_many_options[e].stock,
                    optionsId: this.data.gooddatas.has_many_options[e].id
                }), this.data.optionsMaxCount = this.data.gooddatas.has_many_options[e].stock, this.data.optionsMaxCount > 0 && this.setData({
                    goodsCount: 1
                });
                break;
            }
        }
        this.setData({
            specsManage: t
        });
    },
    setGoodsSpecsBySort: function(t) {
        var a = t.split("_");
        a.sort(function(t, a) {
            return t - a;
        });
        for (var s = "", o = 0; o < a.length; o++) s += a[o] + "_";
        return s = s.substring(0, s.length - 1);
    },
    getMaxCount: function() {
        var t = this.data.specsManage, a = this.data.optionsMaxCount;
        t.length == this.data.gooddatas.has_many_specs.length && (0 == a && this.setData({
            goodsCount: 0
        }), this.data.goodsCount > a && this.setData({
            goodsCount: a
        }));
    },
    OpenLeader: function() {
        wx.navigateTo({
            url: "/packageA/detail_v2/detail_v2?id=" + this.data.gooddatas.goods_id + "&name=69"
        });
    },
    submitAction: function() {
        var t = this.data.gooddatas.goods_id, s = this.data.optionsId, o = this.data.goodsCount;
        if (0 != this.data.optionsMaxCount) if (o <= 0) wx.showToast({
            icon: "none",
            title: "请选择商品数量",
            duration: 1500
        }); else {
            var e = this, i = [];
            i.push(t);
            var d = a.getNetAddresss("from.div-from.isDisplay");
            d += "&goods_ids=" + JSON.stringify(i), a._getNetWork({
                showToastIn: !1,
                url: d,
                success: function(a) {
                    var i = a.data;
                    if (1 == i.result) {
                        var d = i.data;
                        console.log("xxxx", d), i.data.status && !i.data.member_status ? wx.showModal({
                            title: "提示",
                            content: "购买此商品,请补充您的个人信息",
                            success: function(t) {
                                t.confirm ? wx.navigateTo({
                                    url: "/packageB/member/address/myinfo/myinfo?tag=delta"
                                }) : t.cancel && console.log("用户点击取消");
                            }
                        }) : wx.navigateTo({
                            url: "/packageD/buy/myOrder_v2/myOrder_v2?tag=-2&optionsId=" + s + "&goodsId=" + t + "&total=" + o + "&type=grabGroup_join&at_id=" + e.data.gooddatas.activity_id + "&leader_id=" + e.options.id
                        });
                    } else wx.showToast({
                        icon: "none",
                        title: i.msg,
                        duration: 1500
                    });
                },
                fail: function(t) {}
            });
        } else wx.showToast({
            icon: "none",
            title: "商品库存不足",
            duration: 1500
        });
    }
});